package cn.driver.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.driver.domain.Student;
import cn.driver.service.StudentService;
import cn.driver.utils.MyException;
@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	private StudentService studentService;
	
	//添加学员
	@RequestMapping("/regist")
	public Map<Object,Object> regist(String name,String id,String teacher,String schedule,String phone,Integer age,String addr,String gender){
		Map<Object,Object> map = new HashMap<Object,Object>();
		try{
			
				studentService.regist( name,id, teacher,schedule, phone, age, addr, gender);
				map.put("success", true);
			
		}catch (MyException e) {
			e.printStackTrace();
			map.put("success", false);
			map.put("message", e.getMessage());
		}catch(Exception e){
			e.printStackTrace();
		}
		return map;
	}
	
	//遍历学员信息
	@RequestMapping("/list")
	public List<Student> studentInfo(){
		return studentService.studentInfo();
	}
	
	//遍历学员信息
	@RequestMapping("/search")
	public List<Student> stuSearch(String Info){
		return studentService.stuSearch(Info);
	}
	//删除学员
	@RequestMapping("/delete")
	public Map<Object,Object> deleteStu(String id){
		Map<Object,Object> map = new HashMap<Object,Object>();
		try{
			
				studentService.deleteStu(id);
				map.put("success", true);
			
		}catch (MyException e) {
			e.printStackTrace();
			map.put("success", false);
			map.put("message", e.getMessage());
		}catch(Exception e){
			e.printStackTrace();
			map.put("success", false);
			map.put("message", e.getMessage());
		}
		return map;
	}
	//查找单个学员信息
	@RequestMapping("/selectInfo")
	public Student selectInfo(String id){
		return studentService.selectStudent(id);
	}
		//修改学员信息
		@RequestMapping("/update")
		public Map<Object,Object> updateStu(
				String info,String name,String id,String teacher,String schedule,String phone,Integer age,String addr,String gender	){
			Map<Object,Object> map = new HashMap<Object,Object>();
			try{
				
					studentService.updateStu(info,name,id, teacher,schedule, phone, age, addr, gender);
					map.put("success", true);
				
			}catch(Exception e){
				e.printStackTrace();
				map.put("success", false);
				map.put("message", e.getMessage());
			}
			return map;
		}
		//添加学员
		@RequestMapping("/check")
		public Map<Object,Object> check(String id,String name){
			Map<Object,Object> map = new HashMap<Object,Object>();
			try{
				
					studentService.check(id,name);
					map.put("success", true);
				
			}catch (MyException e) {
				e.printStackTrace();
				map.put("success", false);
				map.put("message", e.getMessage());
			}
			return map;
		}
		@RequestMapping("/selectname")
		public Student select(String name){
				
			return studentService.select(name);
		}
}
